package com.example.administrator.znjt.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.administrator.znjt.R;

import java.util.List;

/**
 * Created by Administrator on 2017/5/11.
 */

public class EnvironmentalAdapter extends BaseAdapter {

    private List<Bean> beanList;
    private Context context;

    public EnvironmentalAdapter(List<Bean> beanList, Context context) {
        this.beanList = beanList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return beanList.size();
    }

    @Override
    public Object getItem(int position) {
        return beanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_environmental, null);
        TextView tv_title = (TextView) convertView.findViewById(R.id.tv_title);
        TextView tv_value = (TextView) convertView.findViewById(R.id.tv_value);
        Bean bean = beanList.get(position);
        tv_title.setText(bean.getTitle());
        tv_value.setText(bean.getValue() + "");
        if (position == 0) {
            if (bean.getValue() < 20) {
                tv_value.setBackgroundResource(R.drawable.round_red);
            } else if (bean.getValue() > 26) {
                tv_value.setBackgroundResource(R.drawable.round_red);
            }
        }
        if (position == 1) {
            if (bean.getValue() < 40) {
                tv_value.setBackgroundResource(R.drawable.round_red);
            } else if (bean.getValue() > 60) {
                tv_value.setBackgroundResource(R.drawable.round_red);
            }
        }

        if (position == 2) {
            if (bean.getValue() < 1400) {
                tv_value.setBackgroundResource(R.drawable.round_red);
            } else if (bean.getValue() > 1600) {
                tv_value.setBackgroundResource(R.drawable.round_red);
            }
        }
        if (position == 3) {
            if (bean.getValue() < 5000) {
                tv_value.setBackgroundResource(R.drawable.round_red);
            } else if (bean.getValue() > 10000) {
                tv_value.setBackgroundResource(R.drawable.round_red);
            }
        }
        if (position == 4) {
            if (bean.getValue() < 20) {
                tv_value.setBackgroundResource(R.drawable.round_red);
            } else if (bean.getValue() > 50) {
                tv_value.setBackgroundResource(R.drawable.round_red);
            }
        }
        if (position == 5) {
            if (bean.getValue() > 3) {
                tv_value.setBackgroundResource(R.drawable.round_red);
            }
        }
        return convertView;
    }

    public class Bean {
        private String title;
        private int value;

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public int getValue() {
            return value;
        }

        public void setValue(int value) {
            this.value = value;
        }
    }


}
